﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class AdminControl_OdersDetails : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DataTable dataTable = new DataTable();
        dataTable.Columns.Add("memname");
        dataTable.Columns.Add("phone");
        dataTable.Columns.Add("address");
        dataTable.Columns.Add("bookeddate");
        dataTable.Columns.Add("deliverydate");
        dataTable.Columns.Add("details");
        dataTable.Columns.Add("isfinish");
        dataTable.Columns.Add("bookid");

        ShoppingDataContext spdt = new ShoppingDataContext();
        var ords = from p in spdt.PRO_BOOKEDs
                   join q in spdt.MEMBERs
                   on p.MemberID equals q.MemberID
                   select new { p.BookedID, q.Fullname, p.phone, p.address, 
                                p.bookeddate, p.deliverydate, p.finish};

        foreach (var ord in ords)
        {
            DataRow row = dataTable.NewRow();
            row["bookid"] = ord.BookedID;
            row["memname"] = ord.Fullname;
            row["phone"] = ord.phone;
            row["address"] = ord.address;
            row["bookeddate"] = ord.bookeddate;
            row["deliverydate"] = ord.deliverydate;
            row["details"] = "../AdminTool/OrderDesDetails.aspx?orderid=" + ord.BookedID;
            if (ord.finish == true)
            {
                row["isfinish"] = "~/Images/ImagesForWeb/true.jpg";
            }
            else
            {
                row["isfinish"] = "~/Images/ImagesForWeb/false.jpg";
            }
            dataTable.Rows.Add(row);
        }

        ordersdetails.DataSource = dataTable;
        ordersdetails.DataBind();

    }
    protected void finishclick(object sender, CommandEventArgs e)
    {
        ShoppingDataContext spdt = new ShoppingDataContext();
        PRO_BOOKED pro_booked = spdt.PRO_BOOKEDs.Single(p => p.BookedID == e.CommandArgument.ToString());
        pro_booked.finish = true;
        spdt.SubmitChanges();
        Response.Redirect(Request.Url.AbsoluteUri);
    }

    protected void deleteclick(object sender, CommandEventArgs e)
    {
        ShoppingDataContext spdt = new ShoppingDataContext();
        var pro_booked = from p in spdt.PRO_BOOKEDs
                         where p.BookedID == e.CommandArgument.ToString()
                         select p;
        spdt.PRO_BOOKEDs.DeleteOnSubmit(pro_booked.First());
        spdt.SubmitChanges();
        Response.Redirect(Request.Url.AbsoluteUri);
    }
}
